package com.ruoyi.whzj.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.whzj.mapper.WhAutocommontMapper;
import com.ruoyi.whzj.domain.WhAutocommont;
import com.ruoyi.whzj.service.IWhAutocommontService;
import com.ruoyi.common.core.text.Convert;

/**
 * 自定义评论Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-11-30
 */
@Service
public class WhAutocommontServiceImpl implements IWhAutocommontService 
{
    @Autowired
    private WhAutocommontMapper whAutocommontMapper;

    /**
     * 查询自定义评论
     * 
     * @param id 自定义评论ID
     * @return 自定义评论
     */
    @Override
    public WhAutocommont selectWhAutocommontById(String id)
    {
        return whAutocommontMapper.selectWhAutocommontById(id);
    }

    /**
     * 查询自定义评论列表
     * 
     * @param whAutocommont 自定义评论
     * @return 自定义评论
     */
    @Override
    public List<WhAutocommont> selectWhAutocommontList(WhAutocommont whAutocommont)
    {
        return whAutocommontMapper.selectWhAutocommontList(whAutocommont);
    }

    /**
     * 新增自定义评论
     * 
     * @param whAutocommont 自定义评论
     * @return 结果
     */
    @Override
    public int insertWhAutocommont(WhAutocommont whAutocommont)
    {
        whAutocommont.setId(IdWorker.getId());
        whAutocommont.setCreateTime(DateUtils.getNowDate());
        return whAutocommontMapper.insertWhAutocommont(whAutocommont);
    }

    /**
     * 修改自定义评论
     * 
     * @param whAutocommont 自定义评论
     * @return 结果
     */
    @Override
    public int updateWhAutocommont(WhAutocommont whAutocommont)
    {
        whAutocommont.setUpdateTime(DateUtils.getNowDate());
        return whAutocommontMapper.updateWhAutocommont(whAutocommont);
    }

    /**
     * 删除自定义评论对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWhAutocommontByIds(String ids)
    {
        return whAutocommontMapper.deleteWhAutocommontByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除自定义评论信息
     * 
     * @param id 自定义评论ID
     * @return 结果
     */
    @Override
    public int deleteWhAutocommontById(String id)
    {
        return whAutocommontMapper.deleteWhAutocommontById(id);
    }

    /**
     * 查询自定义评论树列表
     * 
     * @return 所有自定义评论信息
     */
    @Override
    public List<Ztree> selectWhAutocommontTree()
    {
        List<WhAutocommont> whAutocommontList = whAutocommontMapper.selectWhAutocommontList(new WhAutocommont());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (WhAutocommont whAutocommont : whAutocommontList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(Long.parseLong(whAutocommont.getId()));
            ztree.setpId(Long.parseLong(whAutocommont.getPid()));
            ztree.setName(whAutocommont.getCommontTitle());
            ztree.setTitle(whAutocommont.getCommontTitle());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
